<?php 
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of IndexController
*
*/

class Admin_UserController extends Zend_Controller_Action
{

	public function init(){
		$registry = Zend_Registry::getInstance();
		$this->_db = $registry->get('db');
	}
	 
    public function indexAction()
    {
		$this->_helper->layout->setLayout('admin');
		Zend_Loader::loadFile('../application/admin/models/User.php');
        
		$user_model = new User();
		$view_users = $user_model->viewUsers();
        print_r($view_users);
		
		$this->view->view_users = $view_users;
        
    }   
	
	public function adduserAction()
	{
		$this->_helper->layout->setLayout('admin');
		Zend_Loader::loadFile('../application/admin/forms/User.php');
		Zend_Loader::loadFile('../application/admin/models/User.php');
		$user_model = new User();
		$request = $this->getRequest();
		$user_type = $request->getParam('type');
		
		$admin_modules = $user_model->getModules();
		//$admin_modules = unset($admin_modules['4']);
		$this->view->admin_modules = $admin_modules;
		
		$this->view->user_type = $user_type;  	
		
		//$form_user = new Form_User();
		//$this->view->form_user = $form_user;
		
	}
	
	public function doadduserAction()
	{
		Zend_Loader::loadFile('../application/admin/forms/User.php');
		Zend_Loader::loadFile('../application/admin/models/User.php');
		$form_user = new Form_User();
		$request = $this->getRequest();
		$user_type = $request->getParam('type');
		if ($this->getRequest()->isPost()) {            
			if ($form_user->isValid($request->getPost())) {
				$user_model = new User();
				$form_values = $request->getPost();
				//$refer_url = $form_values['refer_url'];
				$user_model->addUser($form_values, $user_type);
				$this->_helper->redirector('/admin/index');
			}
		}
	}
  
}
?>
